<!--
 * @Author: lixb
 * @Date: 2020-09-04 10:14:53
 * @LastEditTime: 2020-09-10 11:47:49
 * @Descripttion: 薪享卡关联订单
-->
<template>
  <div>
    <el-card class="title-search card-box">
      <div>
        <span>订单类型：</span>
        <el-select v-model="orderType" placeholder="请选择">
          <el-option
            v-for="item in orderTypeList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>
      <div>
        <el-button @click="resetDate()">重置</el-button>
        <el-button type="primary" @click="getTableList()">查询</el-button>
        <el-button type="primary" @click="exportExcel()">导出</el-button>
      </div>
    </el-card>
    <el-card class="order-text card-box">
      <div>{{ rowData.date }}</div>
      <div>员工姓名：{{ rowData.realName }}</div>
      <div>所属部门：{{ rowData.deptName }}</div>
      <div>订单总数：{{ rowData.orderNumber }}</div>
      <div>订单总金额(元)：{{ rowData.orderAmount }}</div>
      <div>支付总金额(元)：{{ rowData.payAmount }}</div>
    </el-card>
    <el-card class="main-card">
      <Table
        :table-data="tableData"
        :prop-data="propData"
        :table-index="true"
        :paging-data="pagingData"
        @getTableList="getTableList"
      ></Table>
    </el-card>
  </div>
</template>
<script>
  import Table from '@/components/Table';
  import { downloadBlob } from '@/utils/download';
  import { getAdvanceOrderList, advanceOrderListExcelFile } from '@/api/careCard';
  export default {
    components: { Table },
    data() {
      return {
        orderType: null,
        orderTypeList: [
          {
            label: '薪商城',
            value: 0,
          },
          {
            label: '到店订单',
            value: 1,
          },
          {
            label: '外卖订单',
            value: 2,
          },
          {
            label: '充值薪礼卡',
            value: 3,
          },
        ],
        formInline: {
          userName: '',
          deptName: '',
        },
        rowData: {},
        billDate: '',
        tableData: [],
        propData: [
          {
            prop: 'realName',
            label: '员工姓名',
          },
          {
            prop: 'deptName',
            label: '所属部门',
          },
          {
            prop: 'mobilePhone',
            label: '联系电话',
          },
          {
            prop: 'loginName',
            label: '用户账号',
          },
          {
            prop: 'orderNumber',
            label: '订单总数合计',
          },
          {
            prop: 'orderAmount',
            label: '订单总金额',
          },
          {
            prop: 'payType',
            label: '支付方式',
          },
          {
            prop: 'payAmount',
            label: '支付金额',
          },
        ],
        pagingData: {
          total: 10,
          current: 1,
          size: 10,
        },
      };
    },
    activated() {
      this.rowData = this.$route.query;
      this.getTableList();
    },
    methods: {
      getTableList() {
        let params = {
          billDetailId: this.rowData.billDetailId,
          current: this.pagingData.current,
          size: this.pagingData.size,
          orderType: this.orderType,
          userId: this.rowData.userId,
        };
        getAdvanceOrderList(params).then(res => {
          if (res.status == 200) {
            this.tableData = res.data.records;
            this.pagingData.total = res.data.total;
          }
        });
      },
      resetDate() {
        this.orderType = null;
      },
      async exportExcel() {
        const params = {
          billId: this.rowData.id,
          current: this.pagingData.current,
          size: this.pagingData.size,
          realName: this.formInline.userName,
          deptName: this.formInline.deptName,
        };
        const res = await advanceOrderListExcelFile(params);
        downloadBlob(res.data, res.filename);
        this.$message.success('导出成功！');
      },
    },
  };
</script>
<style lang="scss" scoped>
  .title-search {
    margin-top: 15px;
    div {
      display: inline-block;
      margin-right: 30px;
      span {
        color: #7f848b;
      }
    }
  }
  .order-text {
    margin-top: 15px;
    div {
      margin-right: 30px;
      display: inline-block;
    }
  }
  .main-card {
    margin-top: 15px;
  }
</style>
